//
//  FindPasswdVC.swift
//  NewDelivery
//
//  Created by 天下宅 on 2016/11/15.
//  Copyright © 2016年 天下宅. All rights reserved.
//

import UIKit

class FindPasswdVC: BaseVC {

    let accountTF = UITextField()
    let codeTF = UITextField()
    let newPasswdTF = UITextField()

    override func viewDidLoad() {
        super.viewDidLoad()
        let nav = WKNavView.creatNavView(WithTitle: "忘记密码", vProtocol: self)
        nav.leftBtnEnable = true
        nav.leftImage = UIImage.init(named: "左箭头")
        self.view.addSubview(nav)
        // Do any additional setup after loading the view.
        
        
        self.view.backgroundColor = UIColor.groupTableViewBackground
        
        let v = UIView.init(frame: CGRect.init(x: 0, y: 84, width: screenWidth, height: 180));
        v.addLine(WithColor: UIColor.lightGray, model: [.top,.bottom])
        self.view.addSubview(v)
        
        let hintLabel = UILabel()
        hintLabel.text = "手机号"
        hintLabel.font = UIFont.systemFont(ofSize: 18)
        v.addSubview(hintLabel)
        hintLabel.snp.makeConstraints { (make) in
            make.top.equalToSuperview()
            make.height.equalTo(60)
            make.width.equalTo(80)
            make.left.equalToSuperview().offset(10)
        }
        
        
        let codeBtn = UIButton.button(withTitle: "发送验证码", bgColor: MainColor)
        v.addSubview(codeBtn)
        codeBtn.layer.cornerRadius = 5
        codeBtn.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-10)
            make.top.equalTo(hintLabel).offset(10)
            make.bottom.equalTo(hintLabel).offset(-10)
            make.width.equalTo(100)
        }
        
        v.addSubview(accountTF)
        accountTF.snp.makeConstraints { (make) in
            make.left.equalTo(hintLabel.snp.right)
            make.top.bottom.equalTo(hintLabel)
            make.right.equalTo(codeBtn)
        }
        
        accountTF.placeholder = "请输入账号"
                accountTF.wkMaxCount = 11
                accountTF.enableMaxCount()
//        accountTF.text = "18381084896"
//        
//        
//        passwdTF.text = "123456"
        codeTF.placeholder = "请输入验证码"
        codeTF.isSecureTextEntry = true
        codeTF.wkMaxCount = 4
        codeTF.enableMaxCount()
        
        newPasswdTF.placeholder = "请输入新密码"
        newPasswdTF.isSecureTextEntry = true
        
        let hint1Label = UILabel()
        hint1Label.text = "验证码"
        hint1Label.font = UIFont.systemFont(ofSize: 18)
        v.addSubview(hint1Label)
        hint1Label.snp.makeConstraints { (make) in
            make.top.equalTo(hintLabel.snp.bottom)
            make.height.equalTo(hintLabel)
            make.width.equalTo(hintLabel)
            make.left.equalToSuperview().offset(10)
        }
        
        v.addSubview(codeTF)
        codeTF.snp.makeConstraints { (make) in
            make.left.equalTo(hint1Label.snp.right)
            make.top.bottom.equalTo(hint1Label)
            make.right.equalToSuperview()
        }
        
        
        let hint2Label = UILabel()
        hint2Label.text = "新密码"
        hint2Label.font = UIFont.systemFont(ofSize: 18)
        v.addSubview(hint2Label)
        hint2Label.snp.makeConstraints { (make) in
            make.bottom.equalToSuperview()
            make.height.equalTo(hintLabel)
            make.width.equalTo(hintLabel)
            make.left.equalToSuperview().offset(10)
        }
        
        v.addSubview(newPasswdTF)
        newPasswdTF.snp.makeConstraints { (make) in
            make.left.equalTo(hint2Label.snp.right)
            make.top.bottom.equalTo(hint2Label)
            make.right.equalToSuperview()
        }
        
        
        let btn = UIButton.button(withTitle: "提交", bgColor: MainColor)
        btn.layer.cornerRadius = 5
        self.view.addSubview(btn)
        btn.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-20)
            make.top.equalTo(v.snp.bottom).offset(20)
            make.height.equalTo(60)
        }
        btn.addTarget(self, action: #selector(submit), for: .touchUpInside)
        codeBtn.addTarget(self, action: #selector(getCode), for: .touchUpInside)

    }
    
    func submit()
    {
        if accountTF.text?.characters.count ?? 0 < 11
        {
            self.view.wkMakeToastToCenter(message: "手机号有误")
            return
        }
        
        if newPasswdTF.text?.characters.count ?? 0 < 6
        {
            self.view.wkMakeToastToCenter(message: "密码位数应大于等于6位")
            return
        }
        
        if codeTF.text?.characters.count ?? 0 < 6
        {
            self.view.wkMakeToastToCenter(message: "验证码位数应大于等于6位")
            return
        }
    }

    func getCode()
    {
        //获得验证码
        if accountTF.text?.characters.count ?? 0 < 11
        {
            self.view.wkMakeToastToCenter(message: "手机号有误")
            return
        }
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
